package com.qys.livesMall.common.enums;

import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.exception.enums.ExceptionEnum;
import com.qys.livesMall.common.utils.MessageUtils;

public enum CommonPassFlag {
    审核中((byte) 0, "审核中", "审核中", "Audit"),
    审核未通过((byte) 1, "审核未通过", "审核未通过", "Fail the audit"),
    审核通过((byte) 2, "审核通过", "审核通过", "Pass the audit");



    private Byte status;
    private String error;
    private String zhInfo;
    private String enInfo;

    CommonPassFlag(Byte status, String error, String zhInfo, String enInfo) {
        this.status = status;
        this.error = error;
        this.zhInfo = zhInfo;
        this.enInfo = enInfo;
    }

    public Byte getStatus() {
        return status;
    }
    public String getError() {
        return MessageUtils.message(error);
    }
    public String getZhInfo() {
        return zhInfo;
    }
    public String getEnInfo() {
        return enInfo;
    }


    public static String getStatusInfoByType(Byte status) {
        CommonPassFlag passFlag = getByType(status);
        return null == passFlag ? null : passFlag.getError();
    }

    public static CommonPassFlag getByType(Byte status) {
        for (CommonPassFlag anchorSellTaskStatus : values()) {
            if (anchorSellTaskStatus.getStatus().equals(status)) {
                return anchorSellTaskStatus;
            }
        }
        return null;
    }


    /**
     * nowStatus:当前状态
     * args:需要满足的状态
     */
    public static void checkStatus(Byte nowStatus, CommonPassFlag... args) {
        if (null == nowStatus) {
            throw new QysException(ExceptionEnum.INTERNAL_SERVER_ERROR);
        }
        for (CommonPassFlag s : args) {
            if (nowStatus.equals(s.getStatus())) {
                return;
            }
        }
        throw new QysException(getStatusInfoByType(nowStatus));
    }


    /**
     * 判断状态是否存在
     */
    public static CommonPassFlag statusExists(Byte status) {
        if (null == status) {
            throw new QysException(ExceptionEnum.INTERNAL_SERVER_ERROR);
        }
        CommonPassFlag passFlag = getByType(status);
        if (null == passFlag) {
            throw new QysException(MessageUtils.message("主播带货任务状态错误", status));
        }
        return passFlag;
    }


}
